package com.sharemarking.platform;

import org.springframework.cache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import net.sf.ehcache.config.CacheConfiguration;

@Configuration
public class CacheConfig {
	
	@Bean
	public CacheManager cm(net.sf.ehcache.CacheManager cm) {
		return new EhCacheCacheManager(cm);
	}
	
	@Bean
	public net.sf.ehcache.CacheManager ehcacheCacheManager() {
		CacheConfiguration cacheConfiguration=new CacheConfiguration("default",10000);
		cacheConfiguration.setTimeToLiveSeconds(600);
		net.sf.ehcache.config.Configuration configuration=new net.sf.ehcache.config.Configuration();
		configuration.setDefaultCacheConfiguration(cacheConfiguration);
		net.sf.ehcache.CacheManager cm=net.sf.ehcache.CacheManager.newInstance(configuration);
		cm.addCacheIfAbsent("LOGIN_IMAGE_VALIDATECODE");
		cm.addCacheIfAbsent("LOGIN_FAILURE_TIMES");
		cm.addCacheIfAbsent("REGISTER_IMAGE_VALIDATECODE");
		cm.addCacheIfAbsent("REGISTER_SMS_VALIDATECODE");
		cm.addCacheIfAbsent("PASSWORD_IMAGE_VALIDATECODE");
		cm.addCacheIfAbsent("PASSWORD_SMS_VALIDATECODE");
		cm.addCacheIfAbsent("wechatUserCache");
		cm.addCacheIfAbsent("wechatUserCache");
		cm.addCacheIfAbsent("wechatOpenidCache");
		cm.addCacheIfAbsent("REMOTE_LOGIN_FAILURE_TIMES");
		return cm;
	}
	
}
